Micron Document




Java syntax
part 11/46 · 86.7 KB total
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
/* The following line is equivalent to
if (foo == ColorName.RED) foo = ColorName.BLUE; */
if (foo == RED) foo = BLUE;
}
}

Operators

Operators in Java are similar to those in C++. However, there is no delete operator due to garbage collection mechanisms in Java, and there are no operations on pointers since Java does not support them. Another difference is that Java has an unsigned right shift operator (>>>), while C's right shift operator's signedness is type-dependent. Operators in Java cannot be overloaded.

| Precedence | Operator | Description | Associativity |
|---|---|---|---|
| 1 | () | Method invocation | Left-to-right |
| 1 | [] | Array access | Left-to-right |
| 1 | . | Class member selection | Left-to-right |
| 2 | ++ -- | Postfix increment and decrement [ 1 ] | Left-to-right |
| 3 | ++ -- | Prefix increment and decrement | Right-to-left |
| 3 | + - | Unary plus and minus | Right-to-left |
| 3 | ! ~ | Logical NOT and bitwise NOT | Right-to-left |
| 3 | ( type ) val | Type cast | Right-to-left |
| 3 | new | Class instance or array creation | Right-to-left |
| 4 | * / % | Multiplication, division, and modulus (remainder) | Left-to-right |
| 5 | + - | Addition and subtraction | Left-to-right |
| 5 | + | String concatenation | Left-to-right |
| 6 | << >> >>> | Bitwise left shift, signed right shift and unsigned right shift | Left-to-right |
| 7 | < <= | Relational "less than" and "less than or equal to" | Left-to-right |
| 7 | > >= | Relational "greater than" and "greater than or equal to" | Left-to-right |
| 7 | instanceof | Type comparison | Left-to-right |
| 8 | == != | Relational "equal to" and "not equal to" | Left-to-right |
| 9 | & | Bitwise and logical AND | Left-to-right |
| 10 | ^ | Bitwise and logical XOR (exclusive or) | Left-to-right |
| 11 | / | Bitwise and logical OR (inclusive or) | Left-to-right |
| 12 | && | Logical conditional-AND | Left-to-right |
| 13 | // | Logical conditional-OR | Left-to-right |
| 14 | c ? t : f | Ternary conditional (see ?: ) | Right-to-left |
| 15 | = | Simple assignment | Right-to-left |
| 15 | += -= | Assignment by sum and difference | Right-to-left |
| 15 | *= /= %= | Assignment by product, quotient, and remainder | Right-to-left |
| 15 | <<= >>= >>>= | Assignment by bitwise left shift, signed right shift and unsigned right shift | Right-to-left |
| 15 | &= ^= /= | Assignment by bitwise AND, XOR, and OR | Right-to-left |
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────